package LeetCode.NumOffer;

/**
 * 数组中出现次数超过一半的数
 * @author lumin
 * @date 2022/04/10 19:38
 **/
public class NumOffer39 {
    public int majorityElement(int[] nums) {
        int count = 0;
        int num = 0;
        for (int i = 0; i < nums.length; i++) {
            if(count == 0){
                num = nums[i];
            }
            count += (num == nums[i]) ? 1 : -1;
        }
        return num;
    }
}